package com.hnhy.hnhyscms_ws.controller;

import com.hnhy.hnhyscms_ws.dao.ISpstorageDao;
import com.hnhy.hnhyscms_ws.entity.Spinsto;
import com.hnhy.hnhyscms_ws.entity.Spstorage;
import com.hnhy.hnhyscms_ws.service.ISpinstoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/spinsto")
public class SpinstoController {
    @Autowired
    private ISpinstoService iSpinstoService;
    @Autowired
    private ISpstorageDao iSpstoragService;
    @RequestMapping(value = "/addSpinsto",method= RequestMethod.POST)
    public synchronized void addSpinsto(@RequestParam String productNo, @RequestParam Float amount, @RequestParam String thirdOrderNo){
        Spstorage spstorage=iSpstoragService.getByProductNo(productNo);
        Spinsto spinsto=new Spinsto();
        spinsto.setAmount(amount);
        spinsto.setBand(spstorage.getBand());
        spinsto.setSupplierName(spstorage.getSupplierName());
        spinsto.setSupplierNo(spstorage.getSupplierNo());
        spinsto.setPrice(spstorage.getPrice());
        spinsto.setProductName(spstorage.getProductName());
        spinsto.setProductNo(productNo);
        spinsto.setSpec(spstorage.getSpec());
        spinsto.setThirdOrderNo(thirdOrderNo);
        spinsto.setUnit(spstorage.getUnit());
        spinsto.setTotal(amount*spstorage.getPrice());
        iSpinstoService.addSpinsto(spinsto);
        spstorage.setAmount(amount+spstorage.getAmount());
        iSpstoragService.updateByProductNo(spstorage);
    }
}
